import { createRouter, createWebHashHistory } from 'vue-router'
import routerMap from './routerMap'

const Router = createRouter({
  history: createWebHashHistory(),
  routes: routerMap,
})

Router.beforeEach(async (to, from) => {
  /* const isAuthenticated = localStorage.getItem("user")

  if (
    // 检查用户是否已登录
    !isAuthenticated &&
    // 避免无限重定向
    to.name !== 'Login'
  ) {
    // 将用户重定向到登录页面
    return { name: 'Login' }
  } */

  // 业务页面
  /* const pattern = new RegExp('deptment|plu|customer', 'gi')  //   /deptment|plu|customer/gi
  if (pattern.test(to.name) && !localStorage.getItem('connect')) {
    return { name: 'Connect' }
  } */
})

export default Router
